﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SharedLib.Helpers
{
    public class IOHelper
    {
        public static void CopyFile(string sourceFile, string destinationFile)
        {
            if (File.Exists(sourceFile))
            {
                string destinationDir = Path.GetDirectoryName(destinationFile);
                if (!Directory.Exists(destinationDir))
                {
                    Directory.CreateDirectory(destinationDir);
                }
                File.Copy(sourceFile, destinationFile);
            }
        }

        public static void MoveFile(string sourceFile, string destinationFile)
        {
            if (File.Exists(sourceFile))
            {
                string destinationDir = Path.GetDirectoryName(destinationFile);
                if (!Directory.Exists(destinationDir))
                {
                    Directory.CreateDirectory(destinationDir);
                }
                File.Move(sourceFile, destinationFile);
            }
        }

        public static bool DeleteFolderIfNotEmpty(string path)
        {
            if (Directory.Exists(path))
            {
                if (Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Length == 0)
                {
                    Directory.Delete(path, true);
                    return true;
                }
            }
            return false;
        }
    }
}
